package com.xiaoma.tpo.dao;

import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import com.xiaoma.tpo.baseDao.BaseDaoImpl;
import com.xiaoma.tpo.domain.ForcastUserScore;

@Repository
public class ForcastUserScoreDao extends BaseDaoImpl<ForcastUserScore> {

	private static final Logger LOG = LoggerFactory.getLogger(ForcastUserScore.class);
	
	public List<Map<String, Object>> findAllByUser (String groupIds, Integer userId) {
		
		
		String sql = "select q.question_id as question_id, IFNULL(s.user_id, "+userId+") AS userId, IFNULL(s.score1, 0) AS score1, IFNULL(s.score2, 0) AS score2, IFNULL(s.score3, 0) AS score3" +
				" from fct_question q LEFT JOIN forcast_user_score s " +
				" ON s.question_id = q.question_id  and s.user_id="+ userId +
				" where q.forecast_id in " + groupIds;

		LOG.info("SQL:{} PARAMS:{}", sql);
		return jdbcTemplate.queryForList(sql);
	}
	
}
